﻿using Aop.Api;
using Aop.Api.Request;
using GN.Pay.TradeChannel.AliPay.Request;
using GN.Pay.TradeChannel.AliPay.Request.BizContent;
using GN.Pay.TradeChannel.DefaultImpl;
using GN.Pay.Utils;
using System;

namespace GN.Pay.TradeChannel.AliPay
{
    /// <summary>
    /// 支付宝 Wap 支付服务
    /// </summary>
    [Serializable]
    public class AliPayWapService : AliPayServiceBase
    {
        public override string ChannelId
        {
            get
            {
                return "AliPay.MoblieWap";
            }
        }

        public override string ChannelName
        {
            get
            {
                return "支付宝手机网站支付";
            }
        }

        public override ChannelType ChannelType
        {
            get
            {
                return ChannelType.WebApp | ChannelType.Wap;
            }
        }

        /// <summary>
        /// 手机Web支付
        /// </summary>
        /// <param name="order"></param>
        /// <returns></returns>
        public override ITradePayApplyResult PayApply(IOrderPayApply order)
        {
            var client = new DefaultAopClient(channelConfigure.OpenApiGateWayUrl,
                this.channelConfigure.ConfigureInfo.AppId,
                this.channelConfigure.ConfigureInfo.PrivateKey,
                "json",
                "1.0",
                "RSA",
                this.channelConfigure.ConfigureInfo.PublicKey,
                this.channelConfigure.Encoding.WebName, false);

            var request = new AlipayTradeWapPayRequest();
            request.SetNotifyUrl(channelConfigure.PayNotifyUrl);
            request.SetReturnUrl(channelConfigure.PayWapReturnUrl);
            request.BizContent = new WapPayBizContent(order).ToJson(true);
            var response = client.pageExecute(request, null, "GET");
            return new TradePayApplyResult("", "", response.Body, TradePayApplyResultCallType.Web_Get);
        }
    }
}
